package com.heart.sell.vo;

import com.heart.sell.enums.ResponseCodeEnum;
import lombok.Data;

/**
 * @author Luo Zhen
 * @create 2019-04-23 10:24
 */
@Data
//@JsonInclude(JsonInclude.Include.NON_NULL)
public class ResultVO<T> {

    private Integer code;
    private String msg;
    private T data;

    private ResultVO() {

    }

    private ResultVO(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    private ResultVO(Integer code, T msg) {
        this.code = code;
        this.data = data;
    }

    private ResultVO(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    /**
     * 成功状态
     *
     * @param msg
     * @return
     */
    public static ResultVO successMsg(String msg) {
        return new ResultVO(ResponseCodeEnum.SUCCESS.getCode(), msg);
    }

    /**
     * 成功信息
     *
     * @param data
     * @return
     */
    public static ResultVO success(Object data) {
        return new ResultVO(ResponseCodeEnum.SUCCESS.getCode(), "成功", data);
    }

    /**
     * 失败状态
     *
     * @param msg
     * @return
     */
    public static ResultVO serviceFail(Integer code, String msg) {
        return new ResultVO(code, msg);
    }

    /**
     * 失败状态
     *
     * @param msg
     * @return
     */
    public static ResultVO error(String msg) {
        return new ResultVO(ResponseCodeEnum.FAILED.getCode(), msg);
    }

    /**
     * 失败状态
     *
     * @param code 自定义返回码
     * @param msg
     * @return
     */
    public static ResultVO error(Integer code, String msg) {
        return new ResultVO(code, msg);
    }

}
